
USE [GoldPrice]
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.GoldPriceHtmlContent_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.GoldPriceHtmlContent_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.GoldPriceHtmlContent_Get_List
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: Friday, June 10, 2011

-- Created By: LacViet Design ()
-- Purpose: Gets all records from the GoldPriceHtmlContent table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.GoldPriceHtmlContent_Get_List

AS


				
				SELECT
					[Id],
					[HtmlContent],
					[PostedDate],
					[Url],
					[DomainName],
					[ViewCount]
				FROM
					[dbo].[GoldPriceHtmlContent]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.GoldPriceHtmlContent_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.GoldPriceHtmlContent_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.GoldPriceHtmlContent_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: Friday, June 10, 2011

-- Created By: LacViet Design ()
-- Purpose: Gets records from the GoldPriceHtmlContent table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.GoldPriceHtmlContent_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy IS NULL OR LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Id]'
				END

				-- SQL Server 2005 Paging
				DECLARE @SQL AS nvarchar(MAX)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Id]'
				SET @SQL = @SQL + ', [HtmlContent]'
				SET @SQL = @SQL + ', [PostedDate]'
				SET @SQL = @SQL + ', [Url]'
				SET @SQL = @SQL + ', [DomainName]'
				SET @SQL = @SQL + ', [ViewCount]'
				SET @SQL = @SQL + ' FROM [dbo].[GoldPriceHtmlContent]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Id],'
				SET @SQL = @SQL + ' [HtmlContent],'
				SET @SQL = @SQL + ' [PostedDate],'
				SET @SQL = @SQL + ' [Url],'
				SET @SQL = @SQL + ' [DomainName],'
				SET @SQL = @SQL + ' [ViewCount]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + CONVERT(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				EXEC sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[GoldPriceHtmlContent]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.GoldPriceHtmlContent_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.GoldPriceHtmlContent_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.GoldPriceHtmlContent_Insert
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: Friday, June 10, 2011

-- Created By: LacViet Design ()
-- Purpose: Inserts a record into the GoldPriceHtmlContent table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.GoldPriceHtmlContent_Insert
(

	@Id int   ,

	@HtmlContent ntext   ,

	@PostedDate datetime   ,

	@Url nvarchar (200)  ,

	@DomainName nvarchar (50)  ,

	@ViewCount int   
)
AS


				
				INSERT INTO [dbo].[GoldPriceHtmlContent]
					(
					[Id]
					,[HtmlContent]
					,[PostedDate]
					,[Url]
					,[DomainName]
					,[ViewCount]
					)
				VALUES
					(
					@Id
					,@HtmlContent
					,@PostedDate
					,@Url
					,@DomainName
					,@ViewCount
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.GoldPriceHtmlContent_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.GoldPriceHtmlContent_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.GoldPriceHtmlContent_Update
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: Friday, June 10, 2011

-- Created By: LacViet Design ()
-- Purpose: Updates a record in the GoldPriceHtmlContent table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.GoldPriceHtmlContent_Update
(

	@Id int   ,

	@OriginalId int   ,

	@HtmlContent ntext   ,

	@PostedDate datetime   ,

	@Url nvarchar (200)  ,

	@DomainName nvarchar (50)  ,

	@ViewCount int   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[GoldPriceHtmlContent]
				SET
					[Id] = @Id
					,[HtmlContent] = @HtmlContent
					,[PostedDate] = @PostedDate
					,[Url] = @Url
					,[DomainName] = @DomainName
					,[ViewCount] = @ViewCount
				WHERE
[Id] = @OriginalId 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.GoldPriceHtmlContent_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.GoldPriceHtmlContent_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.GoldPriceHtmlContent_Delete
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: Friday, June 10, 2011

-- Created By: LacViet Design ()
-- Purpose: Deletes a record in the GoldPriceHtmlContent table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.GoldPriceHtmlContent_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[GoldPriceHtmlContent] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.GoldPriceHtmlContent_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.GoldPriceHtmlContent_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.GoldPriceHtmlContent_GetById
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: Friday, June 10, 2011

-- Created By: LacViet Design ()
-- Purpose: Select records from the GoldPriceHtmlContent table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.GoldPriceHtmlContent_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[HtmlContent],
					[PostedDate],
					[Url],
					[DomainName],
					[ViewCount]
				FROM
					[dbo].[GoldPriceHtmlContent]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.GoldPriceHtmlContent_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.GoldPriceHtmlContent_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.GoldPriceHtmlContent_Find
GO

/*
----------------------------------------------------------------------------------------------------
-- Date Created: Friday, June 10, 2011

-- Created By: LacViet Design ()
-- Purpose: Finds records in the GoldPriceHtmlContent table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.GoldPriceHtmlContent_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@HtmlContent ntext   = null ,

	@PostedDate datetime   = null ,

	@Url nvarchar (200)  = null ,

	@DomainName nvarchar (50)  = null ,

	@ViewCount int   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [HtmlContent]
	, [PostedDate]
	, [Url]
	, [DomainName]
	, [ViewCount]
    FROM
	[dbo].[GoldPriceHtmlContent]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([PostedDate] = @PostedDate OR @PostedDate IS NULL)
	AND ([Url] = @Url OR @Url IS NULL)
	AND ([DomainName] = @DomainName OR @DomainName IS NULL)
	AND ([ViewCount] = @ViewCount OR @ViewCount IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [HtmlContent]
	, [PostedDate]
	, [Url]
	, [DomainName]
	, [ViewCount]
    FROM
	[dbo].[GoldPriceHtmlContent]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([PostedDate] = @PostedDate AND @PostedDate is not null)
	OR ([Url] = @Url AND @Url is not null)
	OR ([DomainName] = @DomainName AND @DomainName is not null)
	OR ([ViewCount] = @ViewCount AND @ViewCount is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

